K8s YAML Template
Background
The K8s YAML template is suitable for projects deployed with K8s YAML. It supports users in creating new services on a common template, providing greater scalability.
# New Template
You can abstract the YAML configuration file of K8s resources and define the service based on the K8s YAML template when creating a new service in the project.
- Go to
Assets→Templates→K8s YAMLto enter the management page of the K8s YAML template library. Click the+button → enter the template name → fill in the template content → save the template.

If you use custom variables in the template, you can configure the default values of variables in the custom variable area on the right. For more information, refer to the variable list.

# Variable List
The variable list includes both system-built-in variables and custom variables. Click the key-value pair or YAML file icon below the custom variable to switch the variable view. You can modify the type and default values of the service variables and verify their correctness. It supports four types: string, single choice, boolean, and YAML.
System Built-in Variables: Includes$T-Project$and$T-Service$, which can be used directly in the K8s YAML template. After creating a new service based on a template in the project, these variables will be automatically replaced with the corresponding project name and service name.Custom Variables: Declare them in the form of a YAML code segment and use them in the template in the form of{{.key}}or Go template.
Tip
- When creating a new service based on a template in a project, you can modify the default values of the custom variables
- The key of a custom variable does not support hyphens
- For the use of Go template, refer to the official documentation(opens new window)
In addition to supporting the use of constant values, it also supports using built-in variables in the service configuration to assign values to custom variables in templates. For example, in the following example, using $Service$ to assign values to cmd.

# Using Templates
When creating a new service in the K8s YAML project, you can choose to import services from templates, and refer to using templates to create a new service.
# View the Citation List
Click the Reference List on the right side of the K8s YAML template to view the list of projects and services that reference the template.

# Apply to the Service
Click Apply to Service to update all service configurations with Automatic Synchronization enabled using the latest template content and custom variables.
Tip
- Turn on the
Automatic Synchronizationoperation for the service. Refer to the use template to create a new service - When custom variables are changed, the update logic for service configuration refers to the update service configuration

# Example
# K8s YAML Template
apiVersion: apps/v1
kind: Deployment
metadata:
name: $T-Service$
labels:
app.kubernetes.io/name: $T-Project$
app.kubernetes.io/instance: $T-Service$
annotations:
{{.annotations}}
spec:
selector:
matchLabels:
app.kubernetes.io/name: $T-Project$
app.kubernetes.io/instance: $T-Service$
replicas: {{.replicas_num}}
template:
metadata:
labels:
app.kubernetes.io/name: $T-Project$
app.kubernetes.io/instance: $T-Service$
spec:
containers:
- name: $T-Service$
image: ccr.ccs.tencentyun.com/koderover-public/$T-Service$:latest
imagePullPolicy: Always
env:
- name: DOWNSTREAM_ADDR
value: "b"
- name: HEADERS
value: "x-request-id"
{{- if .skywalking}}
- name: ENHANCE
value: "true"
{{- end}}
command:
- /workspace/{{.cmd}}
ports:
{{- range .ports_config}}
- protocol: {{ .protocol }}
containerPort: {{.container_port}}
{{- end}}
resources:
limits:
memory: {{.memory_limit}}
cpu: {{.cpu_limit}}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Custom Variables
cmd: $Service$
cpu_limit: 50m
memory_limit: 50Mi
replicas_num: 1
skywalking: true
value: value
ports_config:
- protocol: TCP
container_port: 20221
- protocol: UDP
container_port: 21221
annotations: |1-
owner: "John Doe"
team: "DevOps"
2
3
4
5
6
7
8
9
10
11
12
13
14


